#!/usr/bin/python

import os, sys
sys.path.append(os.getcwd() + '/lib')
sys.path.append(os.getcwd() + '/lib/general')
sys.path.append(os.getcwd() + '/lib/gtk')
sys.path.append(os.getcwd() + '/lib/c')

# my libraries
from CFileRunnerGUI import CFileRunnerGUI

def real_main():
	oApp = CFileRunnerGUI()
	oApp.run()
	return

def profile_main():
	# This is the main function for profiling
	# We've renamed our original main() above to real_main()
	import cProfile, pstats, StringIO, logging

	prof = cProfile.Profile()
	prof = prof.runctx("real_main()", globals(), locals())
	stream = StringIO.StringIO()
	stats = pstats.Stats(prof, stream=stream)
	stats.strip_dirs()
	stats.sort_stats("cumulative")  # Or cumulative
	stats.reverse_order()
	stats.print_stats(150)  # 100 = how many to print
	# The rest is optional.
	#stats.dump_stats('profile_stats.dat')
	#stats.print_callees()
	#stats.print_callers()
	print stream.getvalue()
	#logging.info("Profile data:\n%s", stream.getvalue())

if __name__ == "__main__":
	if len(sys.argv) == 2:
		if sys.argv[1] == '-p':
			profile_main()
			# run FileRunner with statistics [profiler enabled]
		else:
			real_main()
	else:
		real_main()
